package com.wuxu.aspectj.java;


import android.util.Log;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;


/**
 * @author wuxu
 * @date 2024/7/9 14:34
 * @description java代码中，捕获kotlin注解标注的kotlin方法
 */
@Aspect
public class AspectMain {
    String TAG = "tttt-AspectMain";
    static final String POINTCUT = "execution(@com.wuxu.aspectj.kotlin.DebugLog * *(..))";

    @Pointcut(POINTCUT)
    public void debugLog(){
        Log.d(TAG, "--debugLog()");
    }

    @Before("debugLog()")
    public void beforeDebugLog(JoinPoint joinPoint) {
        try {
            String className = joinPoint.getThis().getClass().getSimpleName();
            String methodName = joinPoint.getSignature().getName();
            MethodSignature signature = (MethodSignature) joinPoint.getSignature();
            Method method = signature.getMethod();

            Log.e(TAG, "beforeDebugLog: "+className+"."+methodName);

        } catch (Throwable e) {
            Log.e(TAG, "beforeDebugLog: failed on error: ", e);
        }
    }
}
